package cn.smile.controller.basic;

import cn.smile.bean.dto.basic.BasicItemDTO;
import cn.smile.bean.form.basic.item.BasicItemAddForm;
import cn.smile.bean.form.basic.item.BasicItemUpdateForm;
import cn.smile.bean.form.basic.item.QueryBasicItemForm;
import cn.smile.business.basic.IBasicItemService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/basicItem")
public class BasicItemController {

    @Resource
    private IBasicItemService service;

    @PostMapping(value = "addBasicItem")
    public MyResult<Boolean> addBasicItem(@Valid @RequestBody BasicItemAddForm form) {
        return MyResult.OK(service.addBasicItem(form));
    }

    @PostMapping(value = "updateBasicItem")
    public MyResult<Boolean> updateBasicItem(@Valid @RequestBody BasicItemUpdateForm form) {
        return MyResult.OK(service.updateBasicItem(form));
    }

    @PostMapping(value = "getPage")
    public MyResult<IPage<BasicItemDTO>> getPage(@RequestBody QueryBasicItemForm form) {
        return MyResult.OK(service.getPage(form));
    }

    @GetMapping(value = "getBaseItemById")
    public MyResult<BasicItemDTO> getBaseItemById(@RequestParam("id") String id) {
        return MyResult.OK(service.getBaseItemById(id));
    }

    @GetMapping(value = "delBaseItem")
    public MyResult<Boolean> delBaseItem(@RequestParam("id") String id) {
        return MyResult.OK(service.delBaseItem(id));
    }

    @PostMapping(value = "getList")
    public MyResult<List<BasicItemDTO>> getList(@RequestBody QueryBasicItemForm form){
        return MyResult.OK(service.getList(form));
    }
}
